<template>
  <div class="app-container">
    <!-- 卡片列表 -->
    <div class="card-list">
      <el-row :gutter="20">
        <el-col :span="8" v-for="item in dataList" :key="item.id">
          <el-card shadow="hover" class="card-item">
            <div class="card-header">
              <span class="card-title">{{ item.zbbt }}</span>
              <span class="card-date">{{ item.dbrq }}</span>
            </div>
            <div class="card-content">
              <p><strong>项目编号：</strong>{{ item.zbid }}</p>
              <p><strong>中标供应商：</strong>{{ item.gysmc }}</p>
              <p><strong>中标日期：</strong>{{ item.dbrq }}</p>
            </div>
            <div class="card-footer">
              <el-button type="text" @click="viewDetails(item)">查看详情</el-button>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 详情对话框 -->
    <el-dialog title="定标详情" :visible.sync="detailsDialogVisible" width="50%">
      <div v-if="currentDetails">
        <p><strong>项目编号：</strong>{{ currentDetails.zbid }}</p>
        <p><strong>项目名称：</strong>{{ currentDetails.zbbt }}</p>
        <p><strong>中标供应商：</strong>{{ currentDetails.gysmc }}</p>
        <p><strong>定标日期：</strong>{{ currentDetails.dbrq }}</p>
      </div>
      <div v-else>暂无详情</div>
    </el-dialog>
  </div>
</template>

<script>
import { listZb } from '@/api/zbtable';
export default {
  data() {
    return {
      timer: null,
      loading: false,
      dataList: [],
      detailsDialogVisible: false,
      currentDetails: null,
    };
  },
  methods: {
    // 获取定标数据列表
    getList() {
      this.loading = true;
      listZb().then((response) => {
        this.dataList = response.data;
        this.loading = false;
      });
    },
    // 查看详情
    viewDetails(row) {
      this.currentDetails = row;
      this.detailsDialogVisible = true;
    },
  },
  mounted() {
    this.getList();
     // 设置定时器，每两分钟调用一次 getList
     this.timer = setInterval(() => {
      this.getList();
    }, 1 * 60 * 1000); // 2 分钟
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },
};
</script>

<style scoped>
.app-container {
  padding: 20px;
  background-color: #f5f7fa; /* 背景颜色 */
}

.card-list {
  margin-top: 20px;
}

.card-item {
  border-radius: 12px; /* 圆角 */
  overflow: hidden;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* 默认阴影 */
  background-color: #fff; /* 卡片背景色 */
}

.card-item:hover {
  transform: translateY(-5px); /* 悬停浮动效果 */
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); /* 悬停阴影 */
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
  padding: 10px 15px;
  border-bottom: 1px solid #ebeef5; /* 分隔线 */
}

.card-title {
  color: #333;
}

.card-date {
  font-size: 12px;
  color: #909399;
}

.card-content {
  padding: 15px;
}

.card-content p {
  margin: 5px 0;
  font-size: 14px;
  color: #606266;
}

.card-footer {
  text-align: right;
  padding: 10px 15px;
  border-top: 1px solid #ebeef5; /* 分隔线 */
  background-color: #f9fafc; /* 底部背景色 */
}

.card-footer .el-button {
  font-size: 14px;
  color: #409eff;
  padding: 0;
}

.card-footer .el-button:hover {
  text-decoration: underline;
}
</style>